package com.example.repository;

import com.example.domain.Score;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface ScoreRepository extends PagingAndSortingRepository<Score, Integer> {
    @Query(value = "from Score t where t.schedule.id = :scheduleid and t.student.id = :studentid")
    Page<Score> findAllByScheduleAndStudent(@Param(value = "scheduleid") int scheduleid,
                                            @Param(value = "studentid") int studentid,
                                            Pageable pageable);
    @Query(value = "from Score t where t.schedule.id = :scheduleid")
    Page<Score> findAllBySchedule(@Param(value = "scheduleid")int scheduleid,Pageable pageable);
    
    @Query(value = "from Score t where t.schedule.id = :scheduleid")
    List<Score> findAllByScheduleForList(@Param(value = "scheduleid")int scheduleid);
    
    // @Modifying
    // @Query(value = "delete from Score t where t.student.id in :studentids")
    // void deleteByStudent_Id(@Param(value = "studentids")Iterable<Integer> studentids);
    void deleteByStudent_Id(Iterable<Integer> studentids);
    
    
    Iterable<Score> findAllBySchedule_id(Iterable<Integer> scheduleids);
    
    // @Modifying
    // @Query(value = "delete from Score where schedule.id in :scheduleids")
    void deleteBySchedule_IdIn(@Param("scheduleids") Iterable<Integer> scheduleids);
    
    
    // void deleteAllBySch_IdIsIn()
}
